<?php

error_reporting(E_ALL);

/**
 * cn.solor.dig - class.XDigger.php
 *
 * $Id: class.XDigger.php,v 1.2 2008-01-14 15:32:04 rainx Exp $
 *
 * This file is part of cn.solor.dig.
 *
 * Automatic generated with ArgoUML 0.22 on 17.12.2006, 10:07:15
 *
 * @author firstname and lastname of author, <author@example.org>
 */

if (0 > version_compare(PHP_VERSION, '5')) {
    die('This file was generated for PHP 5');
}

/**
 * include BasicAnalyzer
 *
 * @author firstname and lastname of author, <author@example.org>
 */
//require_once('class.BasicAnalyzer.php');

/**
 * include DiggerCacheMysql
 *
 * @author firstname and lastname of author, <author@example.org>
 */
//require_once('class.DiggerCacheMysql.php');


// for fetching page
require_once "HTTP/Request.php";

/**
 * include Analyzer
 *
 * @author firstname and lastname of author, <author@example.org>
 */
//require_once('interface.Analyzer.php');

/**
 * include Digger
 *
 * @author firstname and lastname of author, <author@example.org>
 */
//require_once('interface.Digger.php');

/* user defined includes */
// section 127-0-0-1-1bca60a1:10f8a26e06b:-8000:0000000000000795-includes begin
// section 127-0-0-1-1bca60a1:10f8a26e06b:-8000:0000000000000795-includes end

/* user defined constants */
// section 127-0-0-1-1bca60a1:10f8a26e06b:-8000:0000000000000795-constants begin
// section 127-0-0-1-1bca60a1:10f8a26e06b:-8000:0000000000000795-constants end

/**
 * Short description of class XDigger
 *
 * @access public
 * @author firstname and lastname of author, <author@example.org>
 */
class XDigger
    extends BasicAnalyzer
        implements Digger,
                   Analyzer
{
    // --- ATTRIBUTES ---

    /**
     * Short description of attribute diggers
     *
     * @access public
     * @var array
     */
    public $diggers = array();

    /**
     * Short description of attribute cacher
     *
     * @access public
     * @var Digger
     */
    public $cacher = null;


    // --- OPERATIONS ---

    /// constructor
    function __construct()
    {
        // internal analyser
        global $ALL_ANALYZERS;
        global $OPTIONAL_ANALYZERS;
        // $this->cacher = new DiggerCacheMysql();
        // reg all analyzer here ..... TODO mv it to configurable style
        foreach ($ALL_ANALYZERS as $analyzerClass)
        {
            $this->reg(new $analyzerClass());
        }

        foreach ($OPTIONAL_ANALYZERS as $analyzerClass)
        {
            $this->reg(new $analyzerClass(), true);
        }

    }

    /**
     * Short description of method dig
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param string
     * @return array
     */
    public function dig($url)
    {
        $returnValue = array();

        //$cached      = $this->cacher->dig($url);
        $cached = null; // ignore cache

        if ($cached != null)
        {
            return $cached;
        }

        $this->url  = $url;

        $req        = new Http_Request($url);
        $response   = $req->sendRequest();
        if (!$response) return $returnValue;
        $headers    = $req->getResponseHeader();
        $content    = $req->getResponseBody();
        if (array_key_exists('content-type', $headers) && preg_match('/utf-8/i', $headers['content-type']))
        {
            $this->content = $content;
        }
        else /** hardly consider all other conditions is gbk **/
        {
            // XXX: 改为不做任何处理
            // $this->content = iconv('gbk//IGNORE', 'utf-8//IGNORE', $content);
            $this->content = $content;
        }
        $returnValue= $this->runDiggers();
        return (array) $returnValue;
    }

    /**
     * Short description of method getTitle
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return string
     */
    public function getTitle()
    {
        $returnValue = (string) '';

        return (string) $returnValue;
    }

} /* end of class XDigger */


?>
